[SOLVED] javascript insertBefore() Method

Posted by Robert on Stack Overflow See other posts from Stack Overflow or by Robert
Published on 2009-10-15T19:20:03Z Indexed on 2010/04/12 23:53 UTC
Read the original article Hit count: 270

Filed under:
|

I'm trying to insert a TH as the first column. But so far always put it at the end of all columns. Any help will be appreciate it. Thanks

var someNode  = document.createElement("th");
someNode.innerHTML = "Hello";
var sp = document.getElementById("table").getElementsByTagName("thead")[0].getElementsByTagName("tr")[0];
var ref = document.getElementById("table").getElementsByTagName("thead")[0].getElementsByTagName("tr")[0].getElementsByTagName("th")[0];
sp.insertBefore(someNode,ref);

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about dom